package cn.wolfcode.transfer.util;

import cn.wolfcode.transfer.domain.Employee;
import cn.wolfcode.transfer.domain.LoginNotice;
import cn.wolfcode.transfer.domain.Notice;
import org.springframework.http.ResponseCookie;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;

public class UserContext {
    public static final String USER_IN_SESSION ="USER_IN_SESSION" ;
    public static final String EXPRESSION_IN_SESSION ="EXPRESSION_IN_SESSION" ;
    public static final String NOTICE_IN_SESSION = "NOTICE_IN_SESSION";
    public static HttpSession getSession(){
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        return requestAttributes.getRequest().getSession();
    }
    public static HttpServletResponse getRequest(){
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletResponse response = requestAttributes.getResponse();
        return response;
    }

    public static Employee getCurrentUser(){
        return (Employee) getSession().getAttribute(USER_IN_SESSION);
    }
    public static void setCurrentUser(Employee employee){
        getSession().setAttribute(USER_IN_SESSION,employee);

    }
    public static void setExpressions(List<String> list){
        getSession().setAttribute(EXPRESSION_IN_SESSION,list);
    }
    public static List<String> getExpressions(){
        return (List<String>) getSession().getAttribute(EXPRESSION_IN_SESSION);
    }
    public static void setNotice(LoginNotice list){
        getSession().setAttribute(NOTICE_IN_SESSION,list);
    }
    public static LoginNotice getNotice(){
        return (LoginNotice) getSession().getAttribute(NOTICE_IN_SESSION);
    }
}
